Employment in Canada
Graphs of Employment data in Canada using STATCAN data
Data
STATCAN Table 14-10-0017-01
Prepare Data
# devtools::install_github("derekmichaelwright/agData")
library(agData)# Prep data
myCaption <- "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: STATCAN"
myAreas <- c("Canada", "British Columbia", "Alberta", "Saskatchewan",
"Manitoba", "Nova Scotia","Ontario", "Quebec",
"Newfoundland and Labrador", "New Brunswick",
"Prince Edward Island", "Yukon", "Nunavut",
"Northwest Territories")
myColors_Age <- c("darkgreen", "darkorange", "darkred")
myColors_Sex <- c("palevioletred3","steelblue")
#
d1 <- read.csv("1410001701_databaseLoadingData.csv") %>%
select(Area=GEO, Date=REF_DATE, Measurement=Labour.force.characteristics,
Sex, Age=Age.group, Unit=UOM, Scale=SCALAR_FACTOR, Value=VALUE) %>%
mutate(Area = factor(Area, levels = myAreas),
Date = as.Date(paste0(Date, "-15"), format = "%Y-%m-%d"))
d2 <- d1 %>%
filter(Measurement %in% c("Full-time employment", "Part-time employment")) %>%
mutate(Year = as.numeric(substr(Date, 1, 4))) %>%
group_by(Area, Year, Measurement, Sex, Age) %>%
summarise(Value = sum(Value)) %>% ungroup() %>%
group_by(Area, Year, Sex, Age) %>% mutate(Total = sum(Value)) %>% ungroup() %>%
mutate(Percent = 100 * Value / Total)Canada
Unemployment
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Sex == "Both sexes", Age == "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value)) +
geom_line(size = 0.75, alpha = 0.7, color = "darkgreen") +
scale_y_continuous(breaks = 5:15, minor_breaks = 5:15) +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_01.png", mp, width = 6, height = 4)Males vs. Females
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Sex != "Both sexes", Age == "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Sex)) +
geom_line(size = 0.75, alpha = 0.8) +
scale_color_manual(name = NULL, values = myColors_Sex) +
scale_y_continuous(breaks = 5:15, minor_breaks = 5:15) +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_02.png", mp, width = 6, height = 4)> 2010
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Measurement == "Unemployment rate",
Age == "15 years and over", Sex != "Both sexes", Date > "2010-01-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Sex)) +
geom_line(size = 1, alpha = 0.8) +
scale_color_manual(name = NULL, values = myColors_Sex) +
scale_y_continuous(breaks = 5:15, minor_breaks = 5:15) +
scale_x_date(date_breaks = "year", date_minor_breaks = "year",
date_labels = "%Y") +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_03.png", mp, width = 6, height = 4)By Age
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Sex == "Both sexes", Age != "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Age)) +
geom_line(size = 0.75, alpha = 0.7) +
scale_color_manual(name = NULL, values = myColors_Age) +
scale_y_continuous(breaks = seq(5, 30, by = 5), minor_breaks = 0:35) +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_04.png", mp, width = 6, height = 4)Provinces
Unemployment
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Sex == "Both sexes", Age == "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Area)) +
geom_line(size = 0.5, alpha = 0.7) +
facet_wrap(Area ~ ., ncol = 5) +
scale_y_continuous(breaks = seq(5, 25, 5), minor_breaks = seq(5, 25, 5)) +
theme_agData(legend.position = "none") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_05.png", mp, width = 10, height = 4)> 2010
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Sex == "Both sexes", Age == "15 years and over",
Measurement == "Unemployment rate", Date > "2010-01-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Area)) +
geom_line(size = 0.5, alpha = 0.7) +
facet_wrap(Area ~ ., ncol = 5) +
scale_y_continuous(breaks = seq(5, 25, 5), minor_breaks = seq(5, 25, 5)) +
scale_x_date(minor_breaks = "year") +
theme_agData(legend.position = "none") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_06.png", mp, width = 10, height = 4)Males vs. Females
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Sex != "Both sexes", Age == "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Sex)) +
geom_line(size = 0.4, alpha = 0.8) +
facet_wrap(Area ~ ., ncol = 5) +
scale_color_manual(name = NULL, values = myColors_Sex) +
scale_y_continuous(breaks = seq(5, 25, 5), minor_breaks = seq(5, 25, 5)) +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_07.png", mp, width = 10, height = 4)> 2010
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Measurement == "Unemployment rate",
Age == "15 years and over", Sex != "Both sexes", Date > "2010-01-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Sex)) +
geom_line(size = 1, alpha = 0.8) +
facet_wrap(Area ~ ., ncol = 5) +
scale_color_manual(name = NULL, values = myColors_Sex) +
scale_y_continuous(breaks = seq(5, 25, 5), minor_breaks = seq(5, 25, 5)) +
scale_x_date(date_minor_breaks = "year") +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_08.png", mp, width = 10, height = 4)By Age
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Sex == "Both sexes", Age != "15 years and over",
Measurement == "Unemployment rate")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Age)) +
geom_line(size = 0.4, alpha = 0.7) +
facet_wrap(Area ~ ., ncol = 5) +
scale_color_manual(name = NULL, values = myColors_Age) +
scale_y_continuous(breaks = seq(5, 40, 5), minor_breaks = seq(5, 40, 5)) +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_09.png", mp, width = 10, height = 4)> 2010
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Measurement == "Unemployment rate",
Age != "15 years and over", Sex == "Both sexes", Date > "2010-01-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Age)) +
geom_line(size = 0.75, alpha = 0.7) +
facet_wrap(Area ~ ., ncol = 5) +
scale_color_manual(name = NULL, values = myColors_Age) +
scale_y_continuous(breaks = seq(5, 35, 5), minor_breaks = seq(5, 25, 5)) +
scale_x_date(date_minor_breaks = "year") +
theme_agData(legend.position = "bottom") +
labs(title = "Canadian Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_10.png", mp, width = 10, height = 4)Newfoundland vs. Alberta Youth
# Prep data
xx <- d1 %>%
filter(Area == c("Newfoundland and Labrador","Alberta"),
Measurement == "Unemployment rate",
Age == "15 years and over", Sex != "Both sexes")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value, color = Area)) +
geom_line(size = 1, alpha = 0.7) +
facet_wrap(Sex ~ ., ncol = 5) +
scale_color_manual(name = NULL, values = c("darkred","steelblue")) +
scale_y_continuous(breaks = seq(5, 35, 5), minor_breaks = seq(5, 25, 5)) +
scale_x_date(date_minor_breaks = "year") +
theme_agData(legend.position = "bottom") +
labs(title = "Unemployment Rate", x = NULL,
y = "Percent", caption = myCaption)
ggsave("canada_employment_1_11.png", mp, width = 8, height = 4)Full Time vs. Part Time
Canada
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Sex != "Both sexes", Age == "15 years and over",
Measurement %in% c("Full-time employment", "Part-time employment"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Sex)) +
geom_line(size = 0.5, alpha = 0.8) +
facet_wrap(Measurement ~ ., ncol = 2, scales = "free_y") +
scale_color_manual(name = NULL, values = c("palevioletred3","steelblue")) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada", y = "Million", x = NULL, caption = myCaption)
ggsave("canada_employment_2_01.png", mp, width = 6, height = 4)> 2010
# Prep data
xx <- d1 %>%
filter(Area == "Canada", Sex != "Both sexes", Age == "15 years and over",
Measurement %in% c("Full-time employment", "Part-time employment"),
Date > "2010-01-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Sex)) +
geom_line(size = 0.75, alpha = 0.8) +
facet_wrap(Measurement ~ ., ncol = 2, scales = "free_y") +
scale_color_manual(name = NULL, values = c("palevioletred3","steelblue")) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada", y = "Million", x = NULL, caption = myCaption)
ggsave("canada_employment_2_02.png", mp, width = 6, height = 4)2019 vs > 2019
# Prep data
myMeasures <- c("Full-time employment", "Part-time employment")
yy <- d1 %>%
filter(Area == "Canada", Sex == "Both sexes", Age == "15 years and over",
Date > "2019-03-15", Date < "2020-03-15",
Measurement %in% myMeasures) %>%
group_by(Measurement) %>%
summarise(Value = mean(Value))
xx <- d1 %>%
filter(Area == "Canada", Sex == "Both sexes",
Age == "15 years and over", Date > "2020-02-15",
Measurement %in% myMeasures) %>%
mutate(MonthDiff = ifelse(Measurement == myMeasures[1],
Value - yy$Value[yy$Measurement == myMeasures[1]],
Value - yy$Value[yy$Measurement != myMeasures[1]]),
PosNeg = ifelse(MonthDiff > 0, "Pos", "Neg"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = MonthDiff / 1000, fill = PosNeg)) +
geom_bar(stat = "identity", color = "black", alpha = 0.7) +
scale_fill_manual(values = c("darkred","steelblue")) +
scale_y_continuous(breaks = c(-2,-1.5,-1,-0.5,0,0.5,1)) +
facet_grid(. ~ Measurement) +
theme_agData(legend.position = "none") +
labs(title = "Compared to 2019 Average",
y = "Million", x = NULL, caption = myCaption)
ggsave("canada_employment_2_03.png", mp, width = 8, height = 4)Monthly Change
# Prep data
yy <- d1 %>%
filter(Area == "Canada", Date == "2020-02-15", Age == "15 years and over",
Sex == "Both sexes", Measurement != "Unemployment rate")
#i<-"2020-03-15"
for(i in unique(xx$Date)) {
# Full-time
xi <- xx$Value[xx$Date == i & xx$Measurement == "Full-time employment"] -
yy$Value[yy$Measurement == "Full-time employment"]
xx$PanDiff[xx$Date == i & xx$Measurement == "Full-time employment"] <- xi
# Part-time
xi <- xx$Value[xx$Date == i & xx$Measurement == "Full-time employment"] -
yy$Value[yy$Measurement != "Full-time employment"]
xx$PanDiff[xx$Date == i & xx$Measurement != "Full-time employment"] <- xi
#
yy <- d1 %>%
filter(Area == "Canada", Date == i,
Measurement != "Unemployment rate", Sex == "Both sexes")
}
xx <- xx %>% mutate(PosNeg = ifelse(PanDiff > 0, "Pos", "Neg"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = PanDiff / 1000, fill = PosNeg)) +
geom_bar(stat = "identity", color = "black", alpha = 0.7) +
facet_wrap(Measurement ~ ., scales = "free_y") +
scale_fill_manual(values = c("darkred","steelblue")) +
theme_agData(legend.position = "none") +
labs(title = "Change each month since the start of the pandemic",
y = "Million", x = NULL, caption = myCaption)
ggsave("canada_employment_2_04.png", mp, width = 8, height = 4)# Prep data
myMeasures <- c("Full-time employment", "Part-time employment")
xx <- d2 %>%
filter(Area == "Canada", Sex != "Both sexes",
Age != "15 years and over") %>%
mutate(Measurement = factor(Measurement, levels = rev(myMeasures)))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Percent, fill = Measurement)) +
geom_bar(stat = "identity", color = "black", alpha = 0.6, lwd = 0.2) +
facet_grid(Sex ~ Age, scales = "free_y") +
scale_fill_manual(name = NULL, values = c("darkred","steelblue")) +
theme_agData(legend.position = "bottom") +
labs(title = "Employment in Canada", x = NULL, caption = myCaption)
ggsave("canada_employment_2_05.png", mp, width = 8, height = 4)Provinces
# Prep data
xx <- d1 %>%
filter(Area != "Canada", Sex == "Both sexes",
Age == "15 years and over",
Measurement %in% myMeasures)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Measurement)) +
geom_line(size = 0.4, alpha = 0.7) +
scale_color_manual(name = NULL, values = c("darkred","steelblue")) +
facet_wrap(Area ~ ., scales = "free_y", ncol = 5) +
theme_agData(legend.position = "bottom") +
labs(title = "Compared to 2019 Average",
y = "Million", x = NULL, caption = myCaption)
ggsave("canada_employment_2_06.png", mp, width = 10, height = 4)